package com.example.myapplication;

import android.content.ComponentName;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;

import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

import android.view.View;

import android.view.Menu;
import android.view.MenuItem;

public class MainActivity extends AppCompatActivity {

    PackageManager packageManager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        FloatingActionButton fab = findViewById(R.id.fab);
        packageManager=getPackageManager();
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                try{
                    // 创建 Intent 对象
                    Intent intent = new Intent();
                    // 设置 参数
                    intent.putExtra("username","root");
                    intent.putExtra("password","root");
                    // 设置 动作
                    intent.setAction(Intent.ACTION_MAIN);
                    // 协议 类型 - 文本
                    intent.setType("text/plain");
                    // 空間
                    String packageName = "com.legutech.app";
                    // 活動 全路徑
                    String className = "com.amap.flutter.amap_flutter_map_example.MainActivity";
                    // 參數 對象
                    ComponentName componentName = new ComponentName(packageName, className);
                    intent.setComponent(componentName);
                    // 打开 活动
                    startActivity(intent);
                }catch (Exception e) {
                    System.out.println("异常");
                }
            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}